package com.vc.user.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.vc.commons.exception.BusinessException;
import com.vc.commons.model.BaseResponse;
import com.vc.model.entity.user.User;
import com.vc.user.service.IUserService;

@RestController
@RequestMapping(value="/user")
public class UserController {
	
	@Autowired
	private BaseResponse<Object> baseResponse;

	@Autowired
	private IUserService userService;
	
	@RequestMapping(value = "/findById",method=RequestMethod.GET)
	public Integer add() {
		return userService.add(10,20);
	}
	
	@RequestMapping(value="/save")
	public User save(@RequestBody User user) {
		return userService.add(user);
	}
	
	@RequestMapping(value="/testException")
	public Object testException() {
		throw new BusinessException("测试一下异常!");
	}
	
	@RequestMapping(value="/testTransaction")
	public User testTransaction(Integer age,String username) {
		User user = new User();
		user.setAge(age);
		user.setUsername(username);
		user = userService.add(user);
		return user;
	}
	
	@RequestMapping(value="/testDev")
	public String testDev() {
		
		return "测试热部署";
	}
	
	@RequestMapping(value="/testReturn")
	public BaseResponse<Object> testReturn() {
		baseResponse.setData("测试返回");
		return baseResponse;
	}
}
